package com.gxar.quick.ar.server.base.common.utils;

import java.util.Random;

/**
 * @author linsy
 * @version 1.0
 * @created 2023/11/16 14:42
 */
public class RandomNameUtil {

    /**
     * 随机生成英文字母用户名
     *
     * @param length 名字长度
     * @return 响应
     */
    public static String getStringRandom(int length) {
        StringBuilder val = new StringBuilder();
        Random random = new Random();
        //参数length，表示生成几位随机数
        for (int i = 0; i < length; i++) {
            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
            //输出字母还是数字
            if ("char".equalsIgnoreCase(charOrNum)) {
                //输出是大写字母还是小写字母
                int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
                val.append((char) (random.nextInt(26) + temp));
            } else {
                val.append(random.nextInt(10));
            }
        }
        return val.toString();
    }

    public static void main(String[] args) {
        String stringRandom = getStringRandom(8);
        System.out.println(stringRandom);
    }
}
